<template>
  <div>
    <el-drawer
      title="通知配置"
      size="60%"
      :model="false"
      :visible.sync="dialogVisible"
      :before-close="closeAddDialog"
      :modal-append-to-body="false"
      :close-on-press-escape="false"
      :wrapperClosable="false"
      :destroy-on-close="true"
      :append-to-body="true">
      <el-button type="primary" :disabled="estimate" class="select-template" round @click="templateDialog = true">选择模板
      </el-button>
      <span style="color: red" v-if="estimate">无通知模板可选，请联系管理员前往 "商务中心-全局配置-通知配置" 中进行配置</span>
      <div style="width: 90%;margin: 0 auto;" v-if="offerTemplateConfLoaded || templateSelected">
        <el-form ref="addForm" :model="addForm" label-width="150" :rules="addRules">
          <el-row>
            <el-form-item label="模板名称 :" prop="name">
              <el-input :disabled="true" size="mini" v-model="addForm.name" style="width: 30%"></el-input>
            </el-form-item>
          </el-row>
          <el-row :gutter="20">
            <el-col span="12">
              <el-form-item label="通知方式 :" prop="notice" class="form_item">
                <el-radio-group v-model="addForm.notificeType" @change="changeInformGroup(addForm.notificeType)">
                  <el-radio :label="0">飞书</el-radio>
                  <el-radio :label="1">企业微信</el-radio>
                </el-radio-group>
                <el-checkbox style="margin-left: 20px" checked disabled>系统通知
                </el-checkbox>
              </el-form-item>
            </el-col>
          </el-row>
          <!-- 订单管理-->
          <el-row>
            <el-form-item label="订单管理 :" class="form_item" prop="offerNoticeGroup">
              <div class="switch_item">
                <div style="width: 90px"></div>
                <div>
                  <span class="switch_label">通知群:</span>
                  <el-select size="mini" filterable v-model="addForm.offerNoticeGroup">
                    <el-option
                      v-for="(item,index) in informGroupList"
                      :key="index"
                      :label="item"
                      :value="item">
                    </el-option>
                  </el-select>
                </div>
              </div>
            </el-form-item>
            <!-- 创建订单-->
            <el-form-item class="form_item">
              <div class="switch_item">
                <span class="switch_label Sub_option">状态改变 :</span>
                <el-switch :active-value="100" :inactive-value="0"
                           class="switch" v-model="globalSwitch" :disabled="true" active-color="#13ce66"
                           inactive-color="#ff4949"></el-switch>
                <div>
                  <span class="switch_label">添加抄送方:</span>
                  <el-select size="mini" multiple v-model="globalConf" :disabled="true">
                    <el-option
                      v-for="(item,index) in informRoleList"
                      :key="index"
                      :label="item.roleName"
                      :value="item.roleAlias">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <!-- 编辑订单-->
              <div class="switch_item">
                <span class="switch_label Sub_option">编辑订单 :</span>
                <el-switch :active-value="100" :inactive-value="0"
                           class="switch" v-model="addForm.offerEdit" active-color="#13ce66"
                           inactive-color="#ff4949"></el-switch>
                <div>
                  <span class="switch_label">添加抄送方:</span>
                  <el-select size="mini" multiple v-model="addForm.offerEditNoticeRoles">
                    <el-option
                      v-for="(item,index) in informRoleList"
                      :key="index"
                      :label="item.roleName"
                      :value="item.roleAlias">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <!-- 订单冲突-->
              <div class="switch_item">
                <span class="switch_label Sub_option">订单冲突 :</span>
                <el-switch :active-value="100" :inactive-value="0" class="switch"
                           v-model="addForm.offerConflict"
                           active-color="#13ce66"
                           inactive-color="#ff4949"></el-switch>
                <div>
                  <span class="switch_label">添加抄送方:</span>
                  <el-select size="mini" multiple v-model="addForm.offerConflictNoticeRoles">
                    <el-option
                      v-for="(item,index) in informRoleList"
                      :key="index"
                      :label="item.roleName"
                      :value="item.roleAlias">
                    </el-option>
                  </el-select>
                </div>
              </div>
            </el-form-item>
          </el-row>

          <!-- 需求沟通-->
          <el-row>
            <el-form-item label="需求沟通 :" class="form_item" prop="requestCommunicateNoticeGroup">
              <div class="switch_item">
                <el-switch :active-value="100" :inactive-value="0" class="switch"
                           v-model="addForm.requestCommunicate"
                           active-color="#13ce66"
                           inactive-color="#ff4949" @change="desired"></el-switch>
                <div><span class="switch_label">通知群:</span>
                  <el-select size="mini" filterable v-model="addForm.requestCommunicateNoticeGroup"
                             :disabled="requestSelectDisabled">
                    <el-option
                      v-for="(item,index) in informGroupList"
                      :key="index"
                      :label="item"
                      :value="item">
                    </el-option>
                  </el-select>
                </div>
              </div>
            </el-form-item>
            <el-form-item class="form_item">
              <!-- 创建需求-->
              <div class="switch_item">
                <span class="switch_label Sub_option">创建需求 :</span>
                <el-switch :active-value="100" :inactive-value="0"
                           class="switch" v-model="addForm.requestCreate" active-color="#13ce66"
                           inactive-color="#ff4949" :disabled="requestSwitchDemand"></el-switch>
                <div>
                  <span class="switch_label">添加抄送方:</span>
                  <el-select size="mini" multiple v-model="addForm.requestCreateNoticeRoles"
                             :disabled="requestSelectDisabled">
                    <el-option
                      v-for="(item,index) in informRoleList"
                      :key="index"
                      :label="item.roleName"
                      :value="item.roleAlias">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <!-- 分配任务-->
              <div class="switch_item">
                <span class="switch_label Sub_option">分配任务 :</span>
                <el-switch :active-value="100" :inactive-value="0"
                           class="switch" v-model="addForm.assignTask" active-color="#13ce66"
                           inactive-color="#ff4949" :disabled="requestSwitchDemand"></el-switch>
                <div>
                  <span class="switch_label">添加抄送方:</span>
                  <el-select size="mini" multiple v-model="addForm.assignTaskNoticeRoles"
                             :disabled="requestSelectDisabled">
                    <el-option
                      v-for="(item,index) in informRoleList"
                      :key="index"
                      :label="item.roleName"
                      :value="item.roleAlias">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <!-- 上传成品-->
              <div class="switch_item">
                <span class="switch_label Sub_option">上传成品 :</span>
                <el-switch :active-value="100" :inactive-value="0"
                           class="switch" v-model="addForm.uploadProduct"
                           active-color="#13ce66"
                           inactive-color="#ff4949" :disabled="requestSwitchDemand"></el-switch>
                <div>
                  <span class="switch_label">添加抄送方:</span>
                  <el-select size="mini" multiple v-model="addForm.uploadProductNoticeRoles"
                             :disabled="requestSelectDisabled">
                    <el-option
                      v-for="(item,index) in informRoleList"
                      :key="index"
                      :label="item.roleName"
                      :value="item.roleAlias">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <!-- 制作中素材-->
              <div class="switch_item">
                <span class="switch_label Sub_option" style="margin-left:55px;">制作中素材 :</span>
                <el-switch :active-value="100" :inactive-value="0"
                           class="switch" v-model="addForm.inProduction"
                           active-color="#13ce66"
                           inactive-color="#ff4949" :disabled="requestSwitchDemand"></el-switch>
                <div>
                  <span class="switch_label">添加抄送方:</span>
                  <el-select size="mini" multiple v-model="addForm.inProductionNoticeRoles"
                             :disabled="requestSelectDisabled">
                    <el-option
                      v-for="(item,index) in informRoleList"
                      :key="index"
                      :label="item.roleName"
                      :value="item.roleAlias">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <!-- 成品确认-->
              <div class="switch_item">
                <span class="switch_label Sub_option">成品确认 :</span>
                <el-switch :active-value="100" :inactive-value="0"
                           class="switch" v-model="addForm.productConfirm"
                           active-color="#13ce66"
                           inactive-color="#ff4949" :disabled="requestSwitchDemand"></el-switch>
                <div>
                  <span class="switch_label">添加抄送方:</span>
                  <el-select size="mini" multiple v-model="addForm.productConfirmNoticeRoles"
                             :disabled="requestSelectDisabled">
                    <el-option
                      v-for="(item,index) in informRoleList"
                      :key="index"
                      :label="item.roleName"
                      :value="item.roleAlias">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <!-- 追加需求-->
              <div class="switch_item">
                <span class="switch_label Sub_option">追加需求 :</span>
                <el-switch :active-value="100" :inactive-value="0"
                           class="switch" v-model="addForm.requestAdd" active-color="#13ce66"
                           inactive-color="#ff4949" :disabled="requestSwitchDemand"></el-switch>
                <div>
                  <span class="switch_label">添加抄送方:</span>
                  <el-select size="mini" multiple v-model="addForm.requestAddNoticeRoles"
                             :disabled="requestSelectDisabled">
                    <el-option
                      v-for="(item,index) in informRoleList"
                      :key="index"
                      :label="item.roleName"
                      :value="item.roleAlias">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <!--  内容审核      -->
              <div class="switch_item">
                <span class="switch_label Sub_option">内容审核 :</span>
                <el-switch :active-value="100" :inactive-value="0"
                           class="switch" v-model="addForm.requestContentAudit" active-color="#13ce66"
                           inactive-color="#ff4949" :disabled="requestSwitchDemand"></el-switch>
                <div>
                  <span class="switch_label">添加抄送方:</span>
                  <el-select size="mini" multiple v-model="addForm.requestContentAuditNoticeRoles"
                             :disabled="requestSelectDisabled">
                    <el-option
                      v-for="(item,index) in informRoleList"
                      :key="index"
                      :label="item.roleName"
                      :value="item.roleAlias">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <!-- 编辑需求    -->
              <div class="switch_item">
                <span class="switch_label Sub_option">编辑需求 :</span>
                <el-switch :active-value="100" :inactive-value="0"
                           class="switch" v-model="addForm.requestEdit" active-color="#13ce66"
                           inactive-color="#ff4949" :disabled="requestSwitchDemand"></el-switch>
                <div>
                  <span class="switch_label">添加抄送方:</span>
                  <el-select size="mini" multiple v-model="addForm.requestEditNoticeRoles"
                             :disabled="requestSelectDisabled">
                    <el-option
                      v-for="(item,index) in informRoleList"
                      :key="index"
                      :label="item.roleName"
                      :value="item.roleAlias">
                    </el-option>
                  </el-select>
                </div>
              </div>
            </el-form-item>
          </el-row>
          <!-- 素材审核-->
          <el-row>
            <el-form-item label="素材审核 :" class="form_item" prop="creativeAuditNoticeGroup">
              <div class="switch_item">
                <el-switch :active-value="100" :inactive-value="0"
                           class="switch" v-model="addForm.creativeAudit" active-color="#13ce66"
                           inactive-color="#ff4949" @change="createReview"></el-switch>
                <div>
                  <span class="switch_label">通知群:</span>
                  <el-select size="mini" v-model="addForm.creativeAuditNoticeGroup" filterable :disabled="auditSelectDisabled">
                    <el-option
                      v-for="(item,index) in informGroupList"
                      :key="index"
                      :label="item"
                      :value="item">
                    </el-option>
                  </el-select>
                </div>
              </div>
            </el-form-item>
            <el-form-item class="form_item">
              <!-- 提交审核-->
              <div class="switch_item">
                <span class="switch_label Sub_option">提交审核 :</span>
                <el-switch :active-value="100" :inactive-value="0"
                           class="switch" v-model="addForm.auditSubmit" active-color="#13ce66"
                           inactive-color="#ff4949" :disabled="auditSelectDisabled"></el-switch>
                <div>
                  <span class="switch_label">添加抄送方:</span>
                  <el-select size="mini" multiple v-model="addForm.auditSubmitNoticeRoles"
                             :disabled="auditSelectDisabled">
                    <el-option
                      v-for="(item,index) in informRoleList"
                      :key="index"
                      :label="item.roleName"
                      :value="item.roleAlias">
                    </el-option>
                  </el-select>
                </div>
              </div>
              <!-- 审核结果-->
              <div class="switch_item">
                <span class="switch_label Sub_option">审核结果 :</span>
                <el-switch :active-value="100" :inactive-value="0"
                           class="switch" v-model="addForm.auditResult" active-color="#13ce66"
                           inactive-color="#ff4949" :disabled="auditSelectDisabled"></el-switch>
                <div>
                  <span class="switch_label">添加抄送方:</span>
                  <el-select size="mini" multiple v-model="addForm.auditResultNoticeRoles"
                             :disabled="auditSelectDisabled">
                    <el-option
                      v-for="(item,index) in informRoleList"
                      :key="index"
                      :label="item.roleName"
                      :value="item.roleAlias">
                    </el-option>
                  </el-select>
                </div>
              </div>
            </el-form-item>
          </el-row>
          <el-row style="display: flex;justify-content: flex-end">
            <el-button size="mini" @click="closeAddDialog">取 消</el-button>
            <el-button v-if="!addCheck" size="mini" type="primary" @click="submit">保 存</el-button>
          </el-row>
        </el-form>
      </div>
    </el-drawer>
    <!-- 选择模板弹窗 -->
    <el-dialog
      title="选择模板"
      :visible.sync="templateDialog"
      width="80%"
      :before-close="handleClose"
      modal-append-to-body="false"
      close-on-click-modal="true"
      :append-to-body="true">
      <div v-if="templateDialog">
        <avue-crud ref="multipleTable"
                   v-model="form"
                   :data="data"
                   :option="option"
                   :page.sync="page"
                   :search.sync="search"
                   :table-loading="loading"
                   @search-change="searchChange"
                   @search-reset="searchReset"
                   @current-change="currentChange"
                   @size-change="sizeChange"
                   @refresh-change="refreshChange"
                   @on-load="onLoad"
                   @selection-change="selectionChange">
          <template slot-scope="{type,size,row}" slot="menu">
            <el-button icon="el-icon-view" :size="size" :type="type" @click="checkRow(row)">查 看</el-button>
          </template>
        </avue-crud>
      </div>

      <div style="display: flex;justify-content: center;">
        <el-button type="primary" plain size="medium " @click="handleClose">取消</el-button>
        <el-button type="primary" plain size="medium " @click="saveTemplateData">确定</el-button>
      </div>

    </el-dialog>
    <check-template :checkRow=checkTemplate :checkData=checkData @closeDialog="closeDialog"></check-template>
  </div>
</template>

<script>
import {
  checkNoticeTemplate,
  checkOfferNotice,
  getPage,
  getTemplateInfom,
  selectInformGroup
} from "@/api/business/thirdpartyconf";
import {getList} from "@/api/system/role";
import {getOfferConf, saveOfferConf} from "@/api/business/offer";
import {mapGetters} from "vuex";
import func from '@/util/func'
import CheckTemplate from "@/views/system/components/checkComponent/checkTemplate";
import {refineObject} from "@/util/util";

export default {
  name: "templateConf",
  components: {CheckTemplate},
  props: {
    dialogVisible: {
      type: Boolean
    },
    offerID: {
      type: String
    },
    globalConf: {
      type: Array
    },
    globalSwitch: {
      type: String
    }
  },
  computed: {
    ...mapGetters(["offer"]),
  },
  data() {
    let verifyOfferGroup = (rule, value, callback) => {
      if (!value && (this.addForm.createStatusAlter === 100 || this.addForm.offerEdit === 100 || this.addForm.offerConflict === 100)) {
        callback(new Error('请选择通知群'));
      }
      callback();
    }
    let verifyGroup = (rule, value, callback) => {
      if (!value && this.addForm.requestCommunicate === 100) {
        callback(new Error('请选择通知群'));
      }
      callback();
    }
    let verifyAuditGroup = (rule, value, callback) => {
      if (!value && this.addForm.creativeAudit === 100) {
        callback(new Error('请选择通知群'));
      }
      callback();
    }
    return {
      requestSwitchDemand: false,
      requestSelectDisabled: false,
      auditSwitchDemand: false,
      auditSelectDisabled: false,
      estimate: false,
      checkTemplate: false,
      checkData: {},
      selectionList: {},
      loading: false,
      query: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      search: {},
      form: {},
      data: [],
      option: {
        select: true,
        tip: false,
        selection: true,
        refreshBtn: false,
        columnBtn: false,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        viewBtn: false,
        column: [
          {
            label: '序列号',
            prop: 'id'
          },
          {
            label: '模板名称',
            prop: 'name',
            search: true,
          },
          {
            label: '通知方式',
            prop: 'notificeType',
            search: true,
            type: 'select',
            dicData: [
              {label: "飞书", value: 0},
              {label: "企业微信", value: 1},
            ]
          }
        ]
      },
      templateDialog: false,
      informGroupList: [],
      informRoleList: [],
      addRules: {
        // name: {required: true, message: '请输入模板名称', trigger: 'change'},
        requestCommunicateNoticeGroup: [{
          required: false, validator: verifyGroup, message: '请选择通知群', trigger: 'change',
        }],
        creativeAuditNoticeGroup: [{
          required: false, validator: verifyAuditGroup, message: '请选择通知群', trigger: 'change',
        }],
        offerNoticeGroup: [{
          required: false, validator: verifyOfferGroup, message: '请选择通知群', trigger: 'change',
        }]
      },
      addForm: {
        id: '',
        inProduction: 100,
        createStatusAlter: 100,
        offerEdit: 100,
        offerConflict: 100,
        requestCommunicate: 100,
        requestCreate: 100,
        assignTask: 100,
        uploadProduct: 100,
        productConfirm: 100,
        requestAdd: 100,
        creativeAudit: 100,
        auditSubmit: 100,
        auditResult: 100,
        requestContentAudit: 100,
        requestEdit: 100,
        inProductionNoticeRoles: '',
        name: '',
        notificeType: '',
        offerNotice: '',
        offerNoticeGroup: '',
        offerRole: '',
        offerEditNoticeRoles: '',
        offerConflictNoticeRoles: '',
        requestCommunicateNoticeGroup: '',
        requestCreateNoticeRoles: '',
        assignTaskNoticeRoles: '',
        uploadProductNoticeRoles: '',
        productConfirmNoticeRoles: '',
        requestAddNoticeRoles: '',
        creativeAuditNoticeGroup: '',
        auditSubmitNoticeRoles: '',
        auditResultNoticeRoles: '',
        requestContentAuditNoticeRoles: '',
        requestEditNoticeRoles: '',

        offerId: '',
        // offerNoticeRoles: '',
      },
      templateId: '',
      offerTemplateConfLoaded: false,
      templateSelected: false,
      templateData: '',
      allOfferNoticeConf: []

    }
  },
  watch: {
    dialogVisible: {
      deep: true,
      handler(val) {
        if (val) {
          this.init();
        }
      }
    }
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      getList().then(res => {
        this.informRoleList = res.data.data.records
      })
      if (this.offerID !== '') {
        getOfferConf({offerId: this.offerID}).then(res => {
          let offerNoticeConf = res.data.data;
          if (offerNoticeConf) {
            if (offerNoticeConf.id) {
              this.offerTemplateConfLoaded = true;
              for (let key in offerNoticeConf) {
                this.addForm[key] = offerNoticeConf[key];
                if (key == 'requestContentAudit') {
                  let obj = this.addForm;
                }
              }
              //this.addForm = Object.assign({},offerNoticeConf,this.addForm);
              let data = {
                createStatusAlterNoticeRoles: func.toList(this.addForm.createStatusAlterNoticeRoles),
                offerEditNoticeRoles: func.toList(this.addForm.offerEditNoticeRoles),
                offerConflictNoticeRoles: func.toList(this.addForm.offerConflictNoticeRoles),
                requestCreateNoticeRoles: func.toList(this.addForm.requestCreateNoticeRoles),
                assignTaskNoticeRoles: func.toList(this.addForm.assignTaskNoticeRoles),
                uploadProductNoticeRoles: func.toList(this.addForm.uploadProductNoticeRoles),
                productConfirmNoticeRoles: func.toList(this.addForm.productConfirmNoticeRoles),
                requestAddNoticeRoles: func.toList(this.addForm.requestAddNoticeRoles),
                auditSubmitNoticeRoles: func.toList(this.addForm.auditSubmitNoticeRoles),
                auditResultNoticeRoles: func.toList(this.addForm.auditResultNoticeRoles),
                requestContentAuditNoticeRoles: func.toList(this.addForm.requestContentAuditNoticeRoles),
                requestEditNoticeRoles: func.toList(this.addForm.requestEditNoticeRoles),
                inProductionNoticeRoles: func.toList(this.addForm.inProductionNoticeRoles),
                // offerNoticeRoles: func.toList(this.addForm.offerNoticeRoles),
              }
              Object.assign(this.addForm, data)
              this.getInformGroup(this.addForm.notificeType);
              // this.desired()
              // this.createReview()
            }
            checkNoticeTemplate().then(res => {
              this.templateData = res.data.data
              if (this.templateData === "不存在") {
                this.estimate = true
              }
            })
          }
        });
      }
    },
    //需求沟通全局开关
    desired() {
      if (this.addForm.requestCommunicate === 100) {
        this.addForm.requestCreate = 100
        this.addForm.assignTask = 100
        this.addForm.uploadProduct = 100
        this.addForm.productConfirm = 100
        this.addForm.requestAdd = 100
        this.addForm.requestContentAudit = 100
        this.addForm.requestEdit = 100
        this.addForm.inProduction = 100,
        this.requestSwitchDemand = false
        this.requestSelectDisabled = false
      }
      if (this.addForm.requestCommunicate === 0) {
        this.addForm.requestCreate = 0
        this.addForm.assignTask = 0
        this.addForm.uploadProduct = 0
        this.addForm.productConfirm = 0
        this.addForm.requestAdd = 0
        this.addForm.requestContentAudit = 0
        this.addForm.requestEdit = 0
        this.addForm.inProduction = 0
        this.requestSwitchDemand = true
        this.requestSelectDisabled = true
      }

    },
    //素材审核全局开关
    createReview() {
      if (this.addForm.creativeAudit === 100) {
        this.addForm.auditResult = 100
        this.addForm.auditSubmit = 100
        this.auditSelectDisabled = false
        this.auditSwitchDemand = false
      } else {
        this.addForm.auditResult = 0
        this.addForm.auditSubmit = 0
        this.auditSelectDisabled = true
        this.auditSwitchDemand = true
      }
    },
    //接收checkTemplate子组件的值
    closeDialog(val) {
      this.checkTemplate = val
    },
    /*查看函数*/
    checkRow(row) {
      getTemplateInfom(row.id).then(res => {
        Object.assign(this.checkData, res.data.data)
        let data = {
          createStatusAlterNoticeRoles: res.data.data.createStatusAlterNoticeRoles.split(','),
          offerEditNoticeRoles: res.data.data.offerEditNoticeRoles.split(','),
          offerConflictNoticeRoles: res.data.data.offerConflictNoticeRoles.split(','),
          requestCreateNoticeRoles: res.data.data.requestCreateNoticeRoles.split(','),
          assignTaskNoticeRoles: res.data.data.assignTaskNoticeRoles.split(','),
          uploadProductNoticeRoles: res.data.data.uploadProductNoticeRoles.split(','),
          productConfirmNoticeRoles: res.data.data.productConfirmNoticeRoles.split(','),
          requestAddNoticeRoles: res.data.data.requestAddNoticeRoles.split(','),
          auditSubmitNoticeRoles: res.data.data.auditSubmitNoticeRoles.split(','),
          auditResultNoticeRoles: res.data.data.auditResultNoticeRoles.split(','),
          offerRole: res.data.data.offerRole.split(','),
          requestContentAuditNoticeRoles: res.data.data.requestContentAuditNoticeRoles.split(","),
          requestEditNoticeRoles: res.data.data.requestEditNoticeRoles.split(","),
          inProductionNoticeRoles: res.data.data.inProductionNoticeRoles.split(","),
        }
        Object.assign(this.checkData, data)
        this.checkTemplate = true
      })
    },
    /*保存函数*/
    submit() {
      this.addForm.offerId = this.offerID
      let data = Object.assign({}, this.addForm);
      let newData = {
        templateConfId: this.templateId,
        createStatusAlterNoticeRoles: this.addForm.createStatusAlterNoticeRoles.join(','),
        offerEditNoticeRoles: this.addForm.offerEditNoticeRoles.join(','),
        offerConflictNoticeRoles: this.addForm.offerConflictNoticeRoles.join(','),
        requestCreateNoticeRoles: this.addForm.requestCreateNoticeRoles.join(','),
        assignTaskNoticeRoles: this.addForm.assignTaskNoticeRoles.join(','),
        uploadProductNoticeRoles: this.addForm.uploadProductNoticeRoles.join(','),
        productConfirmNoticeRoles: this.addForm.productConfirmNoticeRoles.join(','),
        requestAddNoticeRoles: this.addForm.requestAddNoticeRoles.join(','),
        auditSubmitNoticeRoles: this.addForm.auditSubmitNoticeRoles.join(','),
        auditResultNoticeRoles: this.addForm.auditResultNoticeRoles.join(','),
        requestContentAuditNoticeRoles: this.addForm.requestContentAuditNoticeRoles.join(","),
        requestEditNoticeRoles: this.addForm.requestEditNoticeRoles.join(","),
        inProductionNoticeRoles: this.addForm.inProductionNoticeRoles.join(",")

      }
      Object.assign(data, newData)

      saveOfferConf(data).then((res) => {
        if (res.data.success) {
          this.$message.success("通知配置保存成功");
          this.$emit('allNotice')
        } else {
          this.$message.error("通知配置保存失败");
        }
      }).finally(() => {
        this.closeAddDialog();
      });
    },
    /*获取->选择通知方式群函数*/
    changeInformGroup(notificeType) {
      this.addForm.offerNoticeGroup = '';
      this.addForm.requestCommunicateNoticeGroup = '';
      this.addForm.creativeAuditNoticeGroup = '';
      this.getInformGroup(notificeType);
    },
    getInformGroup(parameter) {
      selectInformGroup(parameter).then(res => {
        this.informGroupList = res.data.data
      })
    },
    /*回到第一页方法*/
    homepage(){
      this.page ={
        pageSize: 10,
        currentPage: 1,
        total: 0
      }
      this.refreshChange()
    },
    /*确定选择模板方法*/
    saveTemplateData() {
      this.addForm = refineObject(this.addForm, [{from: -1, to: 0}]);
      if (!this.selectionList.name) {
        this.$message({
          type: "warning",
          message: '您没有选择任何模板'
        })
        this.templateDialog = false;
        this.homepage()
        return
      }
      this.selectionList = refineObject(this.selectionList, [{from: -1, to: 0}]);
      this.addForm = Object.assign(this.addForm, this.selectionList);
      this.templateId = this.selectionList.id
      this.addForm.id = '';
      let data = {
        offerRole: func.toList(this.addForm.offerRole),
        createStatusAlterNoticeRoles: func.toList(this.addForm.createStatusAlterNoticeRoles),
        offerEditNoticeRoles: func.toList(this.addForm.offerEditNoticeRoles),
        offerConflictNoticeRoles: func.toList(this.addForm.offerConflictNoticeRoles),
        requestCreateNoticeRoles: func.toList(this.addForm.requestCreateNoticeRoles),
        assignTaskNoticeRoles: func.toList(this.addForm.assignTaskNoticeRoles),
        uploadProductNoticeRoles: func.toList(this.addForm.uploadProductNoticeRoles),
        productConfirmNoticeRoles: func.toList(this.addForm.productConfirmNoticeRoles),
        requestAddNoticeRoles: func.toList(this.addForm.requestAddNoticeRoles),
        auditSubmitNoticeRoles: func.toList(this.addForm.auditSubmitNoticeRoles),
        auditResultNoticeRoles: func.toList(this.addForm.auditResultNoticeRoles),
        requestContentAuditNoticeRoles: func.toList(this.addForm.requestContentAuditNoticeRoles),
        requestEditNoticeRoles: func.toList(this.addForm.requestEditNoticeRoles),
        inProductionNoticeRoles: func.toList(this.addForm.inProductionNoticeRoles),
      }
      Object.assign(this.addForm, data)

      selectInformGroup(this.addForm.notificeType).then(res => {
        this.informGroupList = res.data.data
      })

      this.addForm.offerId = this.offerID;
      this.templateDialog = false;
      this.templateSelected = true;
      this.requestSelectDisabled = this.addForm.requestCommunicate !== 100;
      this.auditSelectDisabled = this.addForm.creativeAudit !== 100;
      this.homepage()
    },
    /*实现单选方法*/
    selectionChange(selection) {
      if (selection.length > 1) {
        const preVal = selection.shift();
        this.$refs.multipleTable.toggleRowSelection(preVal, false);
      }
      this.selectionList = selection[0]
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = false;
      getPage(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        const dataList = res.data.data
        this.page.total = dataList.total
        this.data = dataList.records;
        // this.selectionClear();
      })
    },
    /*选择模板弹窗回调关闭*/
    handleClose() {
      this.page ={
          pageSize: 10,
          currentPage: 1,
          total: 0
      }
      this.refreshChange()
      this.templateDialog = false
    },
    /*通知配置弹窗回调关闭*/
    closeAddDialog() {
      this.$emit('closeAddDialog')
      this.offerTemplateConfLoaded = false;
      this.templateSelected = false;
      if (this.$refs.addForm)
        this.$refs.addForm.resetFields();
      this.dialogVisible = false;
      this.addCheck = false;
    },
  }
}
</script>

<style scoped lang="scss">
/deep/ .el-drawer.rtl {
  overflow: scroll;
}

.form_item {
  padding-left: 10px;
}

.switch_item {
  margin-bottom: 1em;
  display: flex;
  align-items: center;

  .switch {
    padding: 0 20px;
  }

  .switch_label {
    margin-right: 20px;
  }

  .Sub_option {
    margin-left: 5em;
  }
}

.delete_icon {

}

.offer-status-alter {
  margin-top: 20px;
  margin-left: 25px
}

.select-template {
  margin-left: 120px;
  width: 200px;
  margin-bottom: 20px;
}

/deep/ .el-form-item__error {
  margin-top: -15px !important;
  margin-left: 215px !important;
}
</style>
